#!/bin/bash

# Check for a recovery segfault in older versions

. ./common

VDI_NAME="test"
VDI_SIZE="20M"

echo "starting two sheep in the first zone"
for i in `seq 0 1`; do
    $SHEEP $STORE/$i -l level=debug -z 0 -p 700$i -c $DRIVER -y 127.0.0.1
done

echo "starting a sheep in the second zone"
for i in `seq 2 2`; do
    $SHEEP $STORE/$i -l level=debug -z 1 -p 700$i -c $DRIVER -y 127.0.0.1
done

_wait_for_sheep "3"

echo "formatting cluster"
_cluster_format -c 2

echo "creating vdi ${NAME}"
$DOG vdi create ${VDI_NAME} ${VDI_SIZE}

echo "filling ${VDI_NAME} with data"
$QEMU_IO -c "write 0 ${VDI_SIZE}" sheepdog:${VDI_NAME} | _filter_qemu_io

echo "reading back ${VDI_NAME} from second zone"
$QEMU_IO -c "read 0 1m" sheepdog:localhost:7002:${VDI_NAME} | _filter_qemu_io

echo "starting a sheep in the third zone"
for i in `seq 3 3`; do
    $SHEEP $STORE/$i -l level=debug -z 2 -p 700$i -c $DRIVER -y 127.0.0.1
done

_wait_for_sheep 4

echo "check that all sheep are alive"
for i in `seq 0 3`; do
    $DOG cluster info -p 700$i | _filter_cluster_info
done
